package com.glela.ningchongqing;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;

import com.alibaba.fastjson.JSONObject;
import com.glela.common.util.HttpUtil;

public class 素材版本测试 {
//	public final static String url = "http://api.xzhuang.com/v2/yg_platform/";
//	public final static String url = "http://api.test.xzhuang.com/yg_platform/";
//	public final static String url = "http://api.dev.xzhuang.com/yg_platform/";
	public final static String url = "http://localhost:8888/yg_platform/";
	
	public static void main(String[] args) {
		goodsInfo();
//		productInfo();
//		myWallet();
//		listCategory();
//		shareOpenStoreGood();
//		shareActivities();
	}

	public static void shareActivities() {
		JSONObject jo = new JSONObject();
		jo.put("userId", 1594);
		jo.put("activeId", 1);
		try {
			String post = doPost(jo.toJSONString(), url + "shareGoods/shareActivities","application/json");
			System.out.println("shareActivities========"+post);
		} catch (Exception e) {
			System.out.println("shareActivities------------"+e.getMessage());
		}
	}
	
	public static void shareOpenStoreGood() {
		JSONObject jo = new JSONObject();
		jo.put("userId", 1594);
		try {
			String post = doPost(jo.toJSONString(), url + "shareGoods/shareOpenStoreGood","application/json");
			System.out.println("addStoreShareCount========"+post);
		} catch (Exception e) {
			System.out.println("addStoreShareCount------------"+e.getMessage());
		}
	}
	
	public static void listCategory() {
		JSONObject jo = new JSONObject();
		try {
			String post = doPost(jo.toJSONString(), url + "category/listCategory","application/json");
			System.out.println("listCategory========"+post);
		} catch (Exception e) {
			System.out.println("listCategory------------"+e.getMessage());
		}
	}
	
	public static void myWallet() {
		JSONObject jo = new JSONObject();
		jo.put("userId", "671508");
		try {
			String post = doPost(jo.toJSONString(), url + "myMoney/myWallet","application/json");
			System.out.println("myWallet========"+post);
		} catch (Exception e) {
			System.out.println("myWallet----------异常---------"+e.getMessage());
		}
	}
	
	public static void goodsInfo() {
		JSONObject jo = new JSONObject();
		jo.put("userId", "6497");// 207 6497
		jo.put("goodId", "2461");
		jo.put("talentShareGoodId", "");
//		jo.put("productId", 1435);
//		jo.put("froms", "h5");
		try {
			String post = doPost(jo.toJSONString(), url + "goods/getGoodsInfoById","application/json");
			System.out.println("goodsInfo========"+post);
		} catch (Exception e) {
			System.out.println("goodsInfo----------异常---------"+e.getMessage());
		}
	}
	/** 规格  */
	public static void productInfo() {
//		{"goodId":"3367","specInfo":"10431","userId":970185,"shareUserId":"263991"}
		JSONObject jo = new JSONObject();
		jo.put("shareUserId", "263991");
		jo.put("specInfo", "10431");
		jo.put("userId", "970185");
		jo.put("goodId", 3367);
		try {
			String post = HttpUtil.doPost(jo.toJSONString(), url + "product/getProductInfoByGoodIdAndSpecInfo","application/json");
			System.out.println("productInfo========"+post);
		} catch (Exception e) {
			System.out.println("productInfo-------------------"+e.getMessage());
		}
	}
	
	public static String doPost(String content,String url,String contentType) throws IOException {
		StringBuilder result = new StringBuilder();
        URL postUrl = new URL(url);  
        URLConnection con = postUrl.openConnection(); 
        con.setConnectTimeout(5000);
        con.setDoOutput(true);  
        con.setRequestProperty("Pragma", "no-cache");  
        con.setRequestProperty("Cache-Control", "no-cache"); 
        if(contentType!=null)
        {
        	con.setRequestProperty("Content-Type", contentType);  
        }
        OutputStreamWriter out = new OutputStreamWriter(con.getOutputStream());    
        out.write(new String(content.getBytes("UTF-8")));  
        out.flush();  
        out.close();  
        BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));  
        String line = "";  
        for (line = br.readLine(); line != null; line = br.readLine()) {  
        	result = result.append(line);
        }  
		return result.toString();
	}
	
	public static void activePage() {
		JSONObject jo = new JSONObject();
		jo.put("userId", "207");
		jo.put("marketingActivitiesId", 3);
		try {
			String post = HttpUtil.doPost(jo.toJSONString(),url + "marketingActivities/activePage","application/json");
			System.out.println("activePage========"+post);
		} catch (Exception e) {
			System.out.println("activePage----------异常---------"+e.getMessage());
		}
	}
}
